package com.atguigu.gmall.web.all.controller;

import com.atguigu.gmall.model.vo.IndexCategoryVo;
import com.atguigu.gmall.web.all.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @author dyq
 * @description
 * @data 28/1/2022
 */
@Controller
public class IndexController {

    @Autowired
    IndexService indexService;

    @GetMapping({"/","/index.html"})
    public String index(Model model){

        List<IndexCategoryVo> allCategory = indexService.getAllCategory();
        int i = 1;
        for (IndexCategoryVo categoryVo : allCategory) {
            categoryVo.setIndex(i++);
        }
        model.addAttribute("list",allCategory);
        return "index/index";
    }
}
